package com.example.photography.adapter.store;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.example.photography.R;
import com.example.photography.adapter.MyBaseAdapter;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
/**
 * 商品分类页
 * 左侧菜单ListView的适配器
 *
 */
public class MenuAdapter extends MyBaseAdapter {

    private int selectItem = 0;

    public MenuAdapter(List list, Context context) {
        super(list, context);
    }

    public int getSelectItem() {
        return selectItem;
    }

    public void setSelectItem(int selectItem) {
        this.selectItem = selectItem;
    }

    @Override
    public View myGetView(int position, View convertView) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.store_item_menu, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (position == selectItem){
            holder.itemName.setBackgroundColor(Color.WHITE);
            holder.itemName.setTextColor(ContextCompat.getColor(mContext,R.color.green));
        }else {
            holder.itemName.setBackgroundColor(ContextCompat.getColor(mContext,R.color.white));
            holder.itemName.setTextColor(ContextCompat.getColor(mContext,R.color.black));
        }
        holder.itemName.setText((CharSequence) list.get(position));
        return convertView;
    }


    static
    class ViewHolder {
        @BindView(R.id.item_name)
        TextView itemName;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
